From a6dc8ed755661544fc4d610fecf490370f90fa43 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 28 Dec 2014 01:04:10 -0800 Subject: [PATCH] Be sure to include --extern for dev-deps and examples --- src/cargo/ops/cargo_rustc/context.rs | 5 ++-- tests/test_cargo_test.rs | 37 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 70ce7f263..8bcd5d720 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -284,9 +284,10 @@ impl<'a, 'b: 'a> Context<'a, 'b> { target.get_profile().is_custom_build() == pkg_dep.is_build(); // If this dependency is *not* a transitive dependency, then it - // only applies to test targets + // only applies to test/example targets let is_actual_dep = pkg_dep.is_transitive() || - target.get_profile().is_test(); + target.get_profile().is_test() || + target.is_example(); is_correct_dep && is_actual_dep }).filter_map(|pkg| { diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 99874db65..0d31e2018 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -1273,3 +1273,40 @@ test!(test_with_example_twice { execs().with_status(0)); assert_that(&p.bin("examples/foo"), existing_file()); }); + +test!(example_with_dev_dep { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lib] + name = "foo" + test = false + doctest = false + + [dev-dependencies.a] + path = "a" + "#) + .file("src/lib.rs", "") + .file("examples/ex.rs", "extern crate a; fn main() {}") + .file("a/Cargo.toml", r#" + [package] + name = "a" + version = "0.0.1" + authors = [] + "#) + .file("a/src/lib.rs", ""); + + assert_that(p.cargo_process("test").arg("-v"), + execs().with_status(0) + .with_stdout(format!("\ +[..] +[..] +[..] +[..] +{running} `rustc [..] --crate-name ex [..] --extern a=[..]` +", running = RUNNING).as_slice())); +}); -- 2.30.2